/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.upc.dew.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import pe.edu.upc.dew.model.Rol;
import pe.edu.upc.dew.model.Usuario;
import pe.edu.upc.dew.service.UsuarioService;
import pe.edu.upc.dew.service.UsuarioServiceImpl;

/**
 *
 * @author PRIOS
 */
public class LoginServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //Recuperar Parametros
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        /* PrintWriter writer = resp.getWriter();
        writer.println("<h1>Bienvenido: "+username+"</h1>");
        writer.close();*/

        //Llamar al model
        UsuarioService service = new UsuarioServiceImpl();
        Usuario user = service.login(username, password);

        HttpSession session = req.getSession();
        session.setAttribute("user", user);

        req.getRequestDispatcher("bienvenido.jsp").forward(req, resp);

        //ALT+SHIF +F
        //ctr+shif+I

    }
}
